<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane :label="'全部（' + projectNum.totalNum + '）'" name="first">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="项目名称" prop="whitePaperName">
            <el-input
                v-model="queryParams.whitePaperName"
                placeholder="请输入项目名称"
                clearable
                @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="projectList">
          <el-table-column label="编号" align="center" prop="id" />
          <el-table-column label="创建时间" align="center" show-overflow-tooltip prop="createTime" />
          <el-table-column label="项目名称" align="center" show-overflow-tooltip prop="whitePaperName" />
          <el-table-column label="企业名称" align="center" show-overflow-tooltip prop="orgName" />
          <el-table-column label="所在行业" align="center" prop="industry" />
          <el-table-column label="采集数据量" align="center" prop="collectDataNum"/>
          <el-table-column label="有效数据源" align="center" prop="dataSourceNum"/>
          <el-table-column label="汇编时长" align="center" prop="collectTime"/>
          <el-table-column label="编写人" align="center" prop="createBy" />
          <el-table-column label="状态" align="center" prop="projectStatus">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.project_status" :value="scope.row.projectStatus"/>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-view"
                  @click="handleView(scope.row.id)"
                  v-hasPermi="['system:project:query']"
              >查看</el-button>
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleStop(scope.row.id)"
                  v-if="scope.row.projectStatus == '1'"
                  v-hasPermi="['system:project:stop']"
              >停止项目</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane :label="'执行中（' + projectNum.runNum + '）'" name="second">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="项目名称" prop="whitePaperName">
            <el-input
                v-model="queryParams.whitePaperName"
                placeholder="请输入项目名称"
                clearable
                @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="projectList">
          <el-table-column label="编号" align="center" prop="id" />
          <el-table-column label="创建时间" align="center" show-overflow-tooltip  prop="createTime" />
          <el-table-column label="项目名称" align="center" show-overflow-tooltip  prop="whitePaperName" />
          <el-table-column label="企业名称" align="center" show-overflow-tooltip  prop="orgName" />
          <el-table-column label="所在行业" align="center" prop="industry" />
          <el-table-column label="采集数据量" align="center" prop="collectDataNum"/>
          <el-table-column label="有效数据源" align="center" prop="dataSourceNum"/>
          <el-table-column label="汇编时长" align="center" prop="collectTime"/>
          <el-table-column label="编写人" align="center" prop="createBy" />
          <el-table-column label="状态" align="center" prop="projectStatus">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.project_status" :value="scope.row.projectStatus"/>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-view"
                  @click="handleView(scope.row.id)"
                  v-hasPermi="['system:project:query']"
              >查看</el-button>
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleStop(scope.row.id)"
                  v-if="scope.row.projectStatus == '1'"
                  v-hasPermi="['system:project:stop']"
              >停止项目</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane :label="'已完成（' + projectNum.finishNum + '）'" name="third">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="项目名称" prop="whitePaperName">
            <el-input
                v-model="queryParams.whitePaperName"
                placeholder="请输入项目名称"
                clearable
                @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="projectList">
          <el-table-column label="编号" align="center" prop="id" />
          <el-table-column label="创建时间" align="center" show-overflow-tooltip prop="createTime" />
          <el-table-column label="项目名称" align="center" show-overflow-tooltip prop="whitePaperName" />
          <el-table-column label="企业名称" align="center" show-overflow-tooltip prop="orgName" />
          <el-table-column label="所在行业" align="center" prop="industry" />
          <el-table-column label="采集数据量" align="center" prop="collectDataNum"/>
          <el-table-column label="有效数据源" align="center" prop="dataSourceNum"/>
          <el-table-column label="汇编时长" align="center" prop="collectTime"/>
          <el-table-column label="编写人" align="center" prop="createBy" />
          <el-table-column label="状态" align="center" prop="projectStatus">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.project_status" :value="scope.row.projectStatus"/>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-view"
                  @click="handleView(scope.row.id)"
                  v-hasPermi="['system:project:query']"
              >查看</el-button>
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="handleStop(scope.row.id)"
                  v-if="scope.row.projectStatus == '1'"
                  v-hasPermi="['system:project:stop']"
              >停止项目</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改白皮书基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="白皮书名称" prop="whitePaperName">
          <el-input v-model="form.whitePaperName" placeholder="请输入白皮书名称" />
        </el-form-item>
        <el-form-item label="企业/机构名称" prop="orgName">
          <el-input v-model="form.orgName" placeholder="请输入企业/机构名称" />
        </el-form-item>
        <el-form-item label="所在行业" prop="industry">
          <el-input v-model="form.industry" placeholder="请输入所在行业" />
        </el-form-item>
        <el-form-item label="联系地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入联系地址" />
        </el-form-item>
        <el-form-item label="联系邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入联系邮箱" />
        </el-form-item>
        <el-form-item label="企业/机构官网" prop="officialWebsite">
          <el-input v-model="form.officialWebsite" placeholder="请输入企业/机构官网" />
        </el-form-item>
        <el-form-item label="企业/机构微信公众号图片地址" prop="officialAccountImgUrl">
          <el-input v-model="form.officialAccountImgUrl" placeholder="请输入企业/机构微信公众号图片地址" />
        </el-form-item>
        <el-form-item label="企业/机构简介" prop="briefIntroduction">
          <el-input v-model="form.briefIntroduction" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProject, statisticNum, stopProject } from "@/api/whitepaper/project"

export default {
  name: "Project",
  dicts: ['project_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 白皮书基本信息表格数据
      projectList: [],
      projectNum: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        whitePaperName: null,
        projectStatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        whitePaperName: [
          { required: true, message: "白皮书名称不能为空", trigger: "blur" }
        ],
        orgName: [
          { required: true, message: "企业/机构名称不能为空", trigger: "blur" }
        ],
        industry: [
          { required: true, message: "所在行业不能为空", trigger: "blur" }
        ],
        address: [
          { required: true, message: "联系地址不能为空", trigger: "blur" }
        ],
        email: [
          { required: true, message: "联系邮箱不能为空", trigger: "blur" }
        ],
        officialWebsite: [
          { required: true, message: "企业/机构官网不能为空", trigger: "blur" }
        ],
      },
      activeName: 'first'
    }
  },
  created() {
    this.getProjectNum()
    this.getList()
  },
  methods: {
    handleStop(id) {
      stopProject({id:id}).then(res => {
        if(res.code === 200) {
          this.$message.success("停止项目成功");
          this.getProjectNum();
          this.getList();
        }

      })
    },
    handleView(id) {
      this.$router.push({ path: '/project/detail',query:{id:id}})
    },
    handleClick(tab, event) {
      if(this.activeName == 'first') {
        this.queryParams.projectStatus = null
      } else if (this.activeName == 'second') {
        this.queryParams.projectStatus = '1'
      } else if (this.activeName == 'third') {
        this.queryParams.projectStatus = '2'
      }

      this.getList()
    },
    /** 查询白皮书基本信息列表 */
    getList() {
      this.loading = true
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 统计白皮书基本信息数量 */
    getProjectNum() {
      statisticNum().then(response => {
        this.projectNum = response.data
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        whitePaperName: null,
        orgName: null,
        industry: null,
        address: null,
        email: null,
        officialWebsite: null,
        officialAccountImgUrl: null,
        briefIntroduction: null,
        projectStatus: null,
        createBy: null,
        createTime: null,
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    }
  }
}
</script>
